//go:build !windows

/*
@auther fenglei
*/
package xxsys

import (
	"fmt"
	"gitee.com/fenglei-l/ops-util/xxlog"
	"github.com/gogf/gf/v2/util/gconv"
	"github.com/gookit/goutil/sysutil/process"
	"strings"
	"syscall"
)

func ProcessGetId(name string) int {
	return process.PIDByName(name)
}
func ProcessKillPid(pid int) error {
	return process.Kill(pid, syscall.SIGKILL)
}
func ProcessNameId(name string) string {
	command := fmt.Sprintf(`ps aux|grep %s|grep -v 'grep'|awk '{print $2}'`, name)
	s, err := ExecCmdSh(command)
	if err != nil {
		xxlog.ErrorUp366(fmt.Errorf(s, err))
		return ""
	}
	return s
}
func ProcessKill(pid string) error {
	str := strings.Split(pid, "\n")
	for _, v := range str {
		if v != "" {
			_ = process.Kill(gconv.Int(v), syscall.SIGKILL)
		} //end if
	} //end for
	return nil
}
